package com.ocean.service.library.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ocean.dao.library.MessageDao;
import com.ocean.entity.library.Message;
import com.ocean.service.library.MessageService;
import com.ocean.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Project：SchoolManage
 * Package：com.ocean.service.library.impl
 * Author:zy
 * Time:2023/3/3
 */

@Service
public class MessageServiceImpl implements MessageService {
    @Autowired
    private MessageDao messageDao;

    @Override
    public R save(Message message) {
        if (messageDao.insert(message) > 0) {
            return R.ok();
        } else {
            return R.fail("插入留言失败");
        }
    }

    @Override
    public R del(int id) {
        if (messageDao.delete(id)>0) {
            return R.ok();
        }else {
            return R.fail("删除留言失败");
        }
    }

    @Override
    public R update(Message message) {
        if (messageDao.update(message)>0) {
            return R.ok();
        }else {
            return R.fail("更新留言失败");
        }
    }

    @Override
    public R queryPage(int page, int size) {
        PageHelper.startPage(page, size);
        PageInfo<Message> pageInfo = new PageInfo<>(messageDao.selectAll());
        return R.ok(pageInfo);
    }
}
